<?php

use yii\db\Migration;

class m210915_111731_minerva_auth extends Migration
{
    public function up()
    {
        /* 取消外键约束 */
        $this->execute('SET foreign_key_checks = 0');
        
        /* 创建表 */
        $this->createTable('{{%minerva_auth}}', [
            'id' => "bigint(20) unsigned NOT NULL AUTO_INCREMENT",
            'title' => "varchar(100) NULL DEFAULT '' COMMENT '权限名称'",
            'desc' => "varchar(500) NULL DEFAULT '' COMMENT '备注说明'",
            'sort' => "bigint(20) unsigned NULL DEFAULT '0' COMMENT '排序权重'",
            'status' => "tinyint(1) unsigned NULL DEFAULT '1' COMMENT '权限状态(1使用,0禁用)'",
            'is_deleted' => "tinyint(1) NULL DEFAULT '0' COMMENT '0未删除 1已删除'",
            'create_at' => "timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间'",
            'PRIMARY KEY (`id`)'
        ], "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=COMPACT COMMENT='大数据系统-角色表'");
        
        /* 索引设置 */
        $this->createIndex('idx_rf_minerva_auth_title','{{%minerva_auth}}','title',0);
        $this->createIndex('idx_rf_minerva_auth_status','{{%minerva_auth}}','status',0);
        
        
        /* 表数据 */
        
        /* 设置外键约束 */
        $this->execute('SET foreign_key_checks = 1;');
    }

    public function down()
    {
        $this->execute('SET foreign_key_checks = 0');
        /* 删除表 */
        $this->dropTable('{{%minerva_auth}}');
        $this->execute('SET foreign_key_checks = 1;');
    }
}

